package com.example.JavaWebApi.controller.systemController;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.JavaWebApi.core.apiinterceptors.annotation.AllowAnonymous;
import com.example.JavaWebApi.core.apiinterceptors.annotation.Authorize;
import com.example.JavaWebApi.core.commonmodel.ResponseModel;
import com.example.JavaWebApi.model.entity.systemEntity.Userinfo;
import com.example.JavaWebApi.model.querymodel.SystemQueryModel.AuthUserQuery;
import com.example.JavaWebApi.model.querymodel.SystemQueryModel.LoginData;
import com.example.JavaWebApi.model.querymodel.SystemQueryModel.UserInfoQuery;
import com.example.JavaWebApi.service.systemService.IUserinfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 *  前端控制器
 * @author 杨泽
 * @since 2022-06-15
 */
@RestController
@RequestMapping("/api/userinfo")
@Api(tags ="用户控制器")
@Authorize
public class UserinfoController {
 
    @Autowired
    public IUserinfoService UserinfoService;
    @AllowAnonymous
    @PostMapping("Login")
    @ApiOperation("用户登录")
    public ResponseModel<String> login(@RequestBody LoginData loginData){
        return UserinfoService.login(loginData);
    }
    @GetMapping("GetUserList")
    @ApiOperation("获取用户信息list")
    //@IgnoreLog
    public IPage<Userinfo> getUserList(UserInfoQuery query){
        return UserinfoService.getUserList(query);
    }
    @PostMapping("Create")
    @ApiOperation("创建用户信息")
    public Boolean create(@RequestBody Userinfo userinfo){
        return UserinfoService.create(userinfo);
    }
    @PostMapping("Update")
    @ApiOperation("更新用户信息")
    public boolean update(@RequestBody Userinfo userinfo){
        return UserinfoService.update(userinfo);
    }
    @GetMapping("Delete")
    @ApiOperation("删除用户信息")
    public boolean delete(String userId){
        return UserinfoService.delete(userId);
    }
//    @GetMapping("GetAuthorizationUserList")
//    @ApiOperation("获取已授权的用户列表")
//    public IPage<Userinfo> getAuthorizationUserList(@Validated AuthUserQuery query){
//        return UserinfoService.getAuthorizationUserList(query);
//    }
    @PostMapping("UpdateUserPwd")
    @ApiOperation("修改密码")
    public Boolean updateUserPwd(@RequestBody Map<String,String> map){
        return UserinfoService.updateUserPwd(map.get("oldPwd"),map.get("newPwd"));
    }
    @PostMapping("UpdatePersonalInfo")
    @ApiOperation("修改个人信息")
    public ResponseModel updatePersonalInfo(@RequestBody Userinfo userinfo){
        return UserinfoService.updatePersonalInfo(userinfo);
    }
}
